package com.zyg.auth.config;

import com.alibaba.fastjson.support.spring.GenericFastJsonRedisSerializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;

/**
 * ------------------------------
 * 功能：
 * 作者：WF
 * 微信：hbxfwf13590332912
 * 创建时间：2021/12/31-15:02
 * ------------------------------
 */
@Configuration
public class MySpringSessionConfig {

    /**
     * 功能: 定制Cookie序列化器（主要配置DomainName）--->必须配置
     * 参数:
     * 返回值: org.springframework.session.web.http.CookieSerializer
     * 时间: 2021/12/31 15:03
     */
    @Bean
    public CookieSerializer cookieSerializer() {
        DefaultCookieSerializer serializer = new DefaultCookieSerializer();
        serializer.setCookieName("ZEYIGOUCOOKIE");
        serializer.setDomainName("zeyigou.com");
        // serializer.setCookiePath("/");
        // serializer.setDomainNamePattern("^.+?\\.(\\w+\\.[a-z]+)$");
        return serializer;
    }

    /**
     * 功能: 可以选择配置，目的是为了redis显示更好看
     * 参数:
     * 返回值: org.springframework.data.redis.serializer.RedisSerializer<java.lang.Object>
     * 时间: 2021/12/31 15:07
     */
    @Bean
    public RedisSerializer<Object> springSessionDefaultRedisSerializer() {
        // return new GenericJackson2JsonRedisSerializer();
        return new GenericFastJsonRedisSerializer();
    }
}
